
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title btn-success btn-outline panel-success collapse-link" title="展开/收起">
					<h5><span class="redragon-head-title">主生产计划头信息</span>&nbsp;<span style="color: black;">（<i class="fa fa-tag"></i>${requestScope.approveStatusMap[requestScope.prodMpsHead.approveStatus]}）</span></h5>
					<div class="ibox-tools">
						<i class="fa fa-chevron-up"></i> 
					</div>
				</div>

				<div id="ibox-content" class="ibox-content border-bottom" style="padding-bottom: 0px;">
					<form id="form" action="web/prodMpsHead/editProdMpsHead" method="post">
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label inputHeadCodeTitle"><span class="text-danger">*</span><strong>计划编码</strong></label>
							<div class="col-sm-4">
								<input id="mpsHeadCode" name="mpsHeadCode" type="text" class="form-control" value="${requestScope.prodMpsHead.mpsHeadCode}">
							</div>
							
							<label class="col-sm-2 col-form-label inputHeadCodeTitle"><span class="text-danger">*</span><strong>计划名称</strong></label>
							<div class="col-sm-4">
								<input id="mpsName" name="mpsName" type="text" class="form-control" value="${requestScope.prodMpsHead.mpsName}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group row">
							<label class="col-sm-2 col-form-label inputDateTitle"><strong>计划描述</strong></label>
	                        <div class="col-sm-4">
	                        	<textarea id="mpsDesc" name="mpsDesc" rows="2" class="form-control">${requestScope.prodMpsHead.mpsDesc}</textarea>
	                        </div>
	                        
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>状态</strong></label>
	                        <div class="col-sm-4">
	                        	<input type="text" class="form-control" value="${requestScope.statusMap[requestScope.prodMpsHead.status]}" readonly="readonly">
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>
	                    
	                    <div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>制单人</strong></label>
							<div class="col-sm-4">
								<input type="text" class="form-control" value="${requestScope.prodMpsHead.staffName}" readonly="readonly">
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>制单部门</strong></label>
							<div class="col-sm-4">
								<input type="text" class="form-control" value="${requestScope.prodMpsHead.departmentName}" readonly="readonly">
							</div>
						</div>
						<div class="hr-line-dashed"></div>

						<div class="form-group row">
							<div class="col-sm-12 col-sm-offset-2 text-right">
								<button class="btn btn-white btn-lg" type="button" onclick="window.location.href='web/prodMpsHead/getProdMpsHeadList'">返回</button>&nbsp;
								<c:if test="${param.mpsHeadCode==null||param.mpsHeadCode==''||requestScope.prodMpsHead.approveStatus=='UNSUBMIT'||requestScope.prodMpsHead.approveStatus=='REJECT' }">
									<button class="ladda-button ladda-button-demo btn btn-success btn-lg" data-style="expand-right">&nbsp;&nbsp;保存&nbsp;&nbsp;<i class="fa fa-save"></i></button>
								</c:if>
								
								<c:if test="${param.mpsHeadCode!=null&&param.mpsHeadCode!=''}">
									<c:if test="${requestScope.prodMpsHead.approveStatus=='UNSUBMIT'||requestScope.prodMpsHead.approveStatus=='REJECT' }">
										<button id="submitApproveButton" class="btn btn-primary btn-lg" type="button">&nbsp;&nbsp;提交&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodMpsHead.approveStatus=='SUBMIT' }">
										<button class="btn btn-warning btn-lg btn-redragon-approve" type="button" onclick="approveData()">&nbsp;&nbsp;审核通过&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
										<button class="btn btn-danger btn-lg btn-redragon-approve" type="button" onclick="window.location.href='web/prodMpsHead/updateApproveStatus?code=${requestScope.prodMpsHead.mpsHeadCode}&approveStatus=REJECT'">&nbsp;&nbsp;驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodMpsHead.approveStatus=='APPROVE' }">
										<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
									</c:if>
								</c:if>
							</div>
						</div>
						
						
						<input type="hidden" id="status" name="status" value="${requestScope.prodMpsHead.status}">
						<input type="hidden" id="staffCode" name="staffCode" value="${requestScope.prodMpsHead.staffCode}">
						<input type="hidden" id="departmentCode" name="departmentCode" value="${requestScope.prodMpsHead.departmentCode}">
						<input type="hidden" id="mpsHeadId" name="mpsHeadId" value="${requestScope.prodMpsHead.mpsHeadId}">
						<input type="hidden" name="createdDate" value="${requestScope.prodMpsHead.createdDate}">
						<input type="hidden" name="createdBy" value="${requestScope.prodMpsHead.createdBy}">
						<input type="hidden" id="version" value="${requestScope.prodMpsHead.version}">
					</form>
				</div>

				<!-- tab 开始 -->
				<div class="row">
					<div class="col-lg-12">
						<div class="ibox ">
							<div class="ibox-title btn-info btn-outline panel-info">
								<h5 class="redragon-line-title">主生产计划行信息</h5>
								<div class="ibox-tools">
								</div>
							</div>

							<div id="ibox-content1" class="ibox-content border-bottom" style="padding-bottom: 0px;">
								<div class="tabs-container">
									<ul class="nav nav-tabs">
										<li><a class="nav-link active" data-toggle="tab" href="#lineTab" onclick="getLineTab('${requestScope.prodMpsHead.mpsHeadCode}')">行列表</a></li>
									</ul>
									<div id="tabDiv" class="tab-content">
									</div>
								</div>
							</div>
							
						</div>
					</div>
				</div>
				<!-- tab 结束 -->
				
			</div>
		</div>
	</div>
</div>


<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<!-- editPage -->
<script src="js/editPage.js"></script>

<script>
	$(document).ready(function() {
		//初始化inputHeadCode只读
		if("${requestScope.prodMpsHead.mpsHeadCode}"!=""){
			$("#mpsHeadCode").prop("readonly", true);
		}
		
		//初始化select2
		$('.select2').select2({width: "100%"});
		
		//提交审批
		$("#submitApproveButton").click(function(){
			var submitFlag = "Y";
				
			if($("#lineTab tbody tr").length==0){
				submitFlag = "N";
				redragonJS.alert("至少新增一行后，才能提交数据");
			}
			
			//提交
			if(submitFlag=="Y"){
				window.location.href='web/prodMpsHead/updateApproveStatus?code=${requestScope.prodMpsHead.mpsHeadCode}&approveStatus=SUBMIT';
			}
		});
		
		
		
		//表单
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#form").valid();
			//l.ladda('stop');
		});

		$("#form").validate({
			rules : {
				mpsHeadCode : {
					required : true,
					isCode : true,
				},
				mpsName : {
					required : true,
				},
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
			
				//提交
				if(submitFlag=="Y"){
					l.ladda('start');
		        	form.submit();
				}
		    }
		});
		
		//初始化tab
		getLineTab("${requestScope.prodMpsHead.mpsHeadCode}");
	});
	
	//获取行tab
	function getLineTab(code){
		$.ajax({
			type: "post",
			url: "web/prodMpsLine/getProdMpsLineList",
			data: {"mpsHeadCode": code, "version": "${param.version}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				if(data!=""){
					$("#tabDiv").html(data);
					$("#lineTab").addClass("active");
					//隐藏保存按钮
					if(($("#mpsHeadId").val()!=null&&$("#mpsHeadId").val()!=""&&"${requestScope.prodMpsHead.approveStatus}"!="UNSUBMIT"&&"${requestScope.prodMpsHead.approveStatus}"!="REJECT")||
					   $("#mpsHeadId").val()==null||$("#mpsHeadId").val()==""){
						$("#tabDiv .btn").hide();
					}
					initControlAuth();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
	//审批通过
	function approveData(){
		redragonJS.confirm("确认审批通过？", function(){
			window.location.href='web/prodMpsHead/updateApproveStatus?code=${requestScope.prodMpsHead.mpsHeadCode}&approveStatus=APPROVE';
		});
	}
	
	//数据变更
	function alterData(){
		redragonJS.confirm("确认变更数据？", function(){
			window.location.href='web/prodMpsHead/updateApproveStatus?code=${requestScope.prodMpsHead.mpsHeadCode}&approveStatus=UNSUBMIT';
		});
	}
</script>